<template>
  <div :id="id" class="my-chart"></div>
</template>
<script>
var echarts = require('echarts')
export default {
  props: {
    id: {
      type: String,
      default: 'chart'
    },
    option: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initCharts()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initCharts() {
      this.chart = echarts.init(document.getElementById(this.id))
      this.chart.setOption(this.option)
    }
  }
}
</script>
<style lang="scss" scoped>
.my-chart{
  width: 100%;
  height: 100%;
}
</style>
